load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_test")
load("//integration/ts-compat:import-all-entry-points.bzl", "generate_import_all_entry_points_file")

package(default_visibility = ["//visibility:public"])

write_file(
    name = "import-all-entry-points-file",
    out = "import-all-entry-points.ts",
    content = [generate_import_all_entry_points_file()],
)

# List of TypeScript packages that we want to run the compatibility test against.
# The list contains NPM module names that resolve to the desired TypeScript version.
typescript_version_packages = [
    "typescript",
]

# Generates a NodeJS test for each configured TypeScript version.
[
    nodejs_test(
        name = ts_pkg_name,
        args = [ts_pkg_name],
        data = [
            "helpers.mjs",
            "test.mjs",
            ":import-all-entry-points-file",
            "//integration:npm-packages-from-runfiles",
            "//src/cdk:npm_package",
            "//src/cdk-experimental:npm_package",
            "//src/google-maps:npm_package",
            "//src/material:npm_package",
            "//src/material-experimental:npm_package",
            "//src/youtube-player:npm_package",
            "@npm//@bazel/runfiles",
            "@npm//shelljs",
            "@npm//%s" % ts_pkg_name,
            "@npm//@types/node",
        ],
        entry_point = "test.mjs",
    )
    for ts_pkg_name in typescript_version_packages
]
